/*
 * 作者:熊猫
 * 日期:2017 - 3 - 14 11 - 27 - 48
 *
 */

package net.lainiao.morethread.Chapter6.demo3;

import java.util.concurrent.PriorityBlockingQueue;

/**
 * Created by Administrator on 2017/3/14.
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        PriorityBlockingQueue<Event> queue = new PriorityBlockingQueue<>();
        Thread[] threads = new Thread[5];
        for (int i = 0; i < threads.length; i++) {
            Task task = new Task(i, queue);
            threads[i] = new Thread(task);
        }
        for (int i = 0; i < threads.length; i++) {
            threads[i].start();
        }
        for (int i = 0; i < threads.length; i++) {
            threads[i].join();
        }
        System.out.println("Main Queue Size:"+queue.size());
        for (int i = 0; i < 5000; i++) {
            Event event=queue.poll();
            System.out.println("Thread ID:"+event.getThreadId()+" Priority :"+event.getPriority());
        }
        System.out.println("Main Queue Size: "+queue.size());
        System.out.println("Main : End Of the program");
    }
}
